package com.atuguigu.boot3.core.event;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

@Service
public class EventPublisher implements ApplicationEventPublisherAware {
    ApplicationEventPublisher applicationEventPublisher;
    public void sendEvent(ApplicationEvent loginSuccessEvent){
        applicationEventPublisher.publishEvent(loginSuccessEvent);
    }

    /**
     * 会被自动调用,把真正发送事件的底层组件给我们注入进来
     * @param applicationEventPublisher event publisher to be used by this object
     */
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
            this.applicationEventPublisher=applicationEventPublisher;
    }
}
